<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<script>
			function fn() {
				console.time() // 开始计时
				for (let i = 0; i < 1000; i++) {
					document.body.innerHTML +=
						'<div style="color:orange">123123</div>'
				}
				console.timeEnd() // 结束计时
			}
			fn()

			function foo() {
				console.time()
				let arr = []
				for (let i = 0; i < 100000; i++) {
					arr.push('<div style="color:orange">123123</div>')
				}
				// 把数组转换为字符串
				document.body.innerHTML = arr.join('')
				console.timeEnd()
			}
			foo()

			// 字符串拼接，性能并不是很好，每拼接一次，就会在内存中开辟一个空间，存数据
		</script>
	</body>
</html>
